﻿
@{
    Layout = "~/Views/Shared/Master.cshtml";
    string type = ViewData["type"].ToString();
    string titletwo = "";
    switch (type)
    {
        case "0":
            titletwo = "全部订单";
            break;
        case "1":
            titletwo = "今日回访";
            break;
        case "2":
            titletwo = "3日过期";
            break;
        case "3":
            titletwo = "7日过期";
            break;
        case "4":
            titletwo = "15日过期";
            break;
        case "5":
            titletwo = "今日订单";
            break;
        case "6":
            titletwo = "当月订单";
            break;
        default:
            titletwo = "全部订单";
            break;
    }

    ViewBag.Title = titletwo+"|订单列表";
}



<div class="page-content">
    <!-- BEGIN PAGE HEADER-->
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li>
                <a href="~/Home/Main">首页</a>
                <i class="fa fa-angle-double-right"></i>
            </li>
            <li>
                <a href="#">@titletwo</a>
                <i class="fa fa-angle-double-right"></i>
            </li>
        </ul>
    </div>
    <!-- BEGIN PAGE TITLE-->
    <h3 class="page-title">
        订单管理
    </h3>
    <!--biaoge-->
    <div class="portlet light">
        <div class="portlet-title">
            <div class="caption"><i class="fa fa-envelope font-yellow-casablanca"></i><span class="caption-subject bold font-yellow-casablanca">@titletwo</span></div>
            @*<a class="btn green-meadow kuan" href="javascript:;"><i class="fa fa-plus"></i> 新 增</a>*@
        </div>
        <!-- END PAGE TITLE-->
        <div class="search_1">
            <form action="~/Home/GetOrder" method="post" id="grform" class="horizontal-form">
                <input type="hidden" value="@ViewData["type"]" id="type" name="type" />
                <div class="form-body">
                    <div class="row se_le">
                        <!--/span-->
                        <div class="se_pad2">
                            <div class="form-group se_bot">
                                <label class="control-label se_le1">客户姓名</label>
                                <div class="se_pad1 padding_le5">
                                    <input type="text" id="CName" name="CName" class="form-control" placeholder="客户姓名">
                                </div>
                            </div>
                        </div>
                        <div class="se_pad2">
                            <div class="form-group se_bot">
                                <label class="control-label se_le1">星级</label>
                                <div class="se_pad1 padding_le5">
                                    @*<input type="text" id="UserName" name="UserName" class="form-control" placeholder="子账号名">*@
                                    <select class="bs-select form-control" id="Stars" name="Stars" data-width="125px" style="display:block;">
                                        <option value="0" selected="selected">全部</option>
                                        <option value="一级">一级</option>
                                        <option value="二级">二级</option>
                                        <option value="三级">三级</option>
                                        <option value="四级">四级</option>
                                        <option value="五级">五级</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                        @if(ViewData["type"].ToString() != "5")
                        {
                            <div class="se_pad2">
                                <div class="form-group se_bot">
                                    <label class="control-label se_le1">创建时间</label>
                                    <div class="se_pad1 padding_le5">
                                        <input type="text" id="CreateTime" name="CreateTime" class="form-control" placeholder="创建时间">
                                    </div>
                                </div>
                            </div>
                        }
                        

                        <div class="se_pad2">
                            <div class="form-group se_bot">
                                <label class="control-label se_le1">客户手机号</label>
                                <div class="se_pad1 padding_le5">
                                    <input type="text" id="Phone" name="Phone" class="form-control" placeholder="客户手机号">
                                </div>
                            </div>
                        </div>

                        <div class="cx">
                            <div class="form-group se_bot"><a class="btn btn-primary" onclick="ChaXun();" href="javascript:;"><i class="fa fa-search"></i> 查询</a></div>
                        </div>
                        @if (ViewData["type"].ToString() == "0" || ViewData["type"].ToString() == "6")
                        {
                            <div class="cx">
                                <a class="btn default kuan" href="javascript:;" onclick="ExportExcel();"><i class="icon-cloud-upload"></i> 导出</a>
                            </div>
                        }
                    </div>
                </div>
            </form>
        </div>
        <div class="portlet-body">
            <div class="table-scrollable_1 table-scrollable-borderless">
                <table class="table table-striped table-hover table-checkable order-column dataTable no-footer table_ri bordered_bott">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>客户姓名</th>
                            <th>手机号</th>
                            <th>订购产品</th>
                            <th>快递单号</th>
                            <th>回访时间</th>
                            <th>等级</th>
                            <th>支付方式</th>
                            <th>价格</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="tbody"></tbody>
                </table>
                <div style="margin-bottom:50px;" id="fenye">
                    <button class="layui-btn layui-btn-xs" style="float:left" onclick="LastPage();">上一页</button>
                    <div style="padding:inherit;float:left;width:78px;height:38px;"><div style="margin-top:8px;text-align:center;" id="pagecounttext"></div></div>
                    <button class="layui-btn layui-btn-xs" style="float:left" onclick="NextPage();">下一页</button>
                    <div style="height:38px;width:500px;float:left;">
                        <div><span style="float:left;margin-left:10px;margin-top:8px;">跳转至</span></div>
                        <div style="height:38px;">
                            <input type="text" id="pagecount" style="margin-left:20px;margin-top:7px; width:50px;" />
                            <button class="" style="margin-left:20px;margin-top:7px; width:50px;" onclick="JumpPage();">确定</button>
                        </div>
                    </div>
                    @if (type == "5")
                    {
                        <div style="height:38px;float:right;">
                            <span style="color:orangered">今日已营收（@ViewData["MoneySum"]）</span>
                        </div>
                    }
                </div>
            </div>

        </div>
    </div>
</div>


<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/layui/layui.js"></script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#CreateTime' //指定元素
        });
    });
</script>
<script>
    var pageindex = 1;
    var pagecount;
    $(function () {
        pageindex = 1;
        GetPage();
    });
    function GetPage() {
        $.ajax({
            url: "/Home/GetOrderPage",
            data: {
                pageindex: pageindex,
                type: $("#type").val(),
                CreateTime: $("#CreateTime").val(),
                Phone: $("#Phone").val(),
                CName: $("#CName").val(),
                Stars: $("#Stars").val()
            },
            success: function (result) {
                if (result.totalcount>0) {
                    var str = ToHtml(result.list);
                    $("#tbody").html('');
                    $("#tbody").html(str);
                    $("#pagecounttext").text(pageindex + "/" + result.pagecount);
                    pagecount = result.pagecount;
                    $("#fenye").show();
                } else {
                    $("#tbody").html('暂无数据');
                    $("#fenye").hide();
                }
            }
        });
    }
    function ChaXun() {
        pageindex = 1;
        GetPage();
    }
    function LastPage() {
        if (pageindex > 1) {
            pageindex--;
            GetPage();
        }
    }
    function NextPage() {
        if (pageindex < pagecount) {
            pageindex++;
            GetPage();
        }
    }
    function JumpPage() {
        var c = $("#pagecount").val();
        if (!isNaN(c) && c >= 1 && c <= pagecount) {
            pageindex = c;
            GetPage();
        }
    }

    function ToHtml(data) {
        var str = "";
        $.each(data, function (i, item) {
            str += "<tr><td>" + (i + 1) + "</td>";
            str += "<td>" + item.CustomerName + "</td>";
            str += "<td>" + item.Phone + "</td>";
            str += "<td>" + item.GoodName + "</td>";
            str += "<td>" + item.ExpressNumber + "</td>";
            str += "<td>" + item.VisitTime + "</td>";
            str += "<td>" + item.Stars + "</td>";
            str += "<td>" + item.PayWay + "</td>";
            str += "<td>" + item.Price + "</td>";
            str += '<td><div class="btn-group"><button class="btn btn-default btn-xs btn_ri" onclick="GetById(' + item.Id + ');" type="button"><i class="fa fa-share"></i>查看</button>';
            str += '<div class="btn-group"><button class="btn btn-default dropdown-toggle btn-xs" data-toggle="dropdown" type="button" aria-expanded="false">';
            str += '<i class="fa fa-ellipsis-horizontal"></i>更多<i class="fa fa-angle-down"></i></button>';
            str += '<ul class="dropdown-menu pull-right dropdown_wid"><li><a href="javascript:;" onclick="UpdateById(' + item.Id + ');"><i class="fa fa-edit"></i> 修改 </a></li>';
            str += '<li><a href="javascript:;" onclick="FollowUp(' + item.Id + ');"><i class="fa fa-pencil"></i> 跟进 </a></li><li><a href="javascript:;" onclick="Delete(' + item.Id + ');"><i class="glyphicon glyphicon-trash"></i> 删除 </a></li></ul></div></div></td></tr>';
        })
        return str;
    }

    function ExportExcel() {
        $.ajax({
            url: "/Home/ExportExcel",
            data: {
                CreateTime: $("#CreateTime").val(),
                Phone: $("#Phone").val(),
                CName: $("#CName").val(),
                type: $("#type").val()
            },
            success: function (result) {
                if (result.success) {
                    window.open(result.url);
                } else {
                    layer.msg(result.msg, { icon: 2 });
                    console.log(result.res);
                }
            }
        });
    }

    function GetById(id) {
        window.location.href = "/Home/GetOrderById?id=" + id;
    }

    function UpdateById(id) {
        window.location.href = "/Home/GetOrderByIdToUpdate?id=" + id;
    }

    function FollowUp(id) {
        window.location.href = "/Home/AddVisit?OrderId=" + id;
        //var url = '/Home/AddVisit?Id=' + id;
        //layer.open({
        //    type: 2,
        //    title: false,
        //    shadeClose: true,
        //    shade: [0.5],
        //    maxmin: false, //开启最大化最小化按钮
        //    area: ['700px', '400px'],
        //    content: url
        //});
    }

    //function Delete(id) {
    //    layer.confirm('请再次确认是否删除此订单', {
    //        btn: ['确定', '取消'] //按钮
    //    }, function () {
    //        $.ajax({
    //            url: "/Home/DeleteOrder",
    //            type: "post",
    //            data: { OrderId: id },
    //            success: function (result) {
    //                if (result.success) {
    //                    layer.msg('删除成功', { icon: 1 });
    //                    setTimeout("location.reload();", 1000);
    //                }
    //            }

    //        });
    //        }

     function Delete(id) {
         layer.confirm('请再次确认是否删除此订单？', {
             btn: ['确定', '取消'] //按钮
         }, function () {
             $.ajax({
                 url: "/Home/DeleteOrder",
                 type: "post",
                 data: { OrderId: id },
                 success: function (result) {
                     if (result.success) {
                         layer.msg('删除成功', { icon: 1 });
                         setTimeout("location.reload();", 1000)
                     }
                 }

             });
         }, function () {
             
         });
        }
</script>